﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class Admin_Addwork : System.Web.UI.Page
{
    AccessDAO dao = new AccessDAO();
    protected void Page_Load(object sender, EventArgs e)
    {
        IsAdmin.Admin();

        if (!Page.IsPostBack)
        {
    
        }
    }
    //修改
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string name = this.txtName.Text;
        string zw = this.txtZw.Text;
        string bz = this.txtBz.Text;
        string subm = this.drpType.SelectedValue;
        string content = this.FCKeditor1.Value;
        string picture = this.FileUpload1.PostedFile.FileName;
        string fileName = "images/" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();

        if (!name.Equals(""))
        {
            if (!picture.Equals(""))
            {
                if (Path.GetExtension(picture).Equals(".gif") || Path.GetExtension(picture).Equals(".jpg") || Path.GetExtension(picture).Equals(".jpeg") || Path.GetExtension(picture).Equals(".png"))
                {
                    fileName += Path.GetExtension(picture);
                    string sql = "insert into workMan(name,workzw,workbz,worksubm,picture,content) values('" + name + "','" + zw + "','" + bz + "','" + subm + "','" + fileName + "','" + content + "')";

                    if (dao.getComm(sql) != 0)
                    {
                        this.FileUpload1.PostedFile.SaveAs(Server.MapPath("~/") + "\\" + fileName);
                        Server.Transfer("ygMessage.aspx");
                    }
                    else
                    {
                        RegisterStartupScript("check", "<script language='javascript'>alert('添加成功');</script>");
                    }
                }
                else
                {
                    RegisterStartupScript("check", "<script language='javascript'>alert('将图片格式改为*.jpg或*.gif或*.jpeg或*.png');</script>");
                }
            }
            else
            {
                picture = "images/nopic.gif";
                string sql = "insert into workMan(name,workzw,workbz,worksubm,picture,content) values('" + name + "','" + zw + "','" + bz + "','" + subm + "','" + picture + "','" + content + "')";

                if (dao.getComm(sql) != 0)
                {
                    this.FileUpload1.PostedFile.SaveAs(Server.MapPath("~/") + "\\" + fileName);
                    Server.Transfer("ygMessage.aspx");
                }
                else
                {
                    RegisterStartupScript("check", "<script language='javascript'>alert('添加成功');</script>");
                }
            }
        }
        else
        {
            RegisterStartupScript("check", "<script language='javascript'>alert('填写姓名');</script>");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Server.Transfer("ygMessage.aspx");
    }
}
